import { AppDataSource } from '../config/database';
import { DeviceControlCapability } from '../entity/DeviceControlCapability';

export async function initControlCapability() {
  const repo = AppDataSource.getRepository(DeviceControlCapability);
  const count = await repo.count();
  if (count > 0) {
    console.log('[INIT] 控制属性表已有数据，跳过初始化');
    return;
  }

  const data: DeviceControlCapability[] = [
    // 小米温湿度计
    { type: 'mi_temp_hum_sensor', operation: 'temperature' },
    { type: 'mi_temp_hum_sensor', operation: 'humidity' },

    // 空气质量检测仪
    { type: 'mi_air_sensor', operation: 'pm25' },
    { type: 'mi_air_sensor', operation: 'temperature' },
    { type: 'mi_air_sensor', operation: 'humidity' },

    // 小米/美的 空调
    { type: 'mi_ac', operation: 'online' },
    { type: 'mi_ac', operation: 'power' },
    { type: 'mi_ac', operation: 'target_temperature' },
    { type: 'mi_ac', operation: 'mode' },
    { type: 'mi_ac', operation: 'fan_speed' },

    { type: 'midea_ac', operation: 'online' },
    { type: 'midea_ac', operation: 'power' },
    { type: 'midea_ac', operation: 'target_temperature' },
    { type: 'midea_ac', operation: 'mode' },
    { type: 'midea_ac', operation: 'fan_speed' },

    // 小米/美的 加湿器
    { type: 'mi_humidifier', operation: 'online' },
    { type: 'mi_humidifier', operation: 'power' },
    { type: 'mi_humidifier', operation: 'status' },
    { type: 'mi_humidifier', operation: 'mode' },
    { type: 'mi_humidifier', operation: 'target_humidity' },

    { type: 'midea_humidifier', operation: 'online' },
    { type: 'midea_humidifier', operation: 'power' },
    { type: 'midea_humidifier', operation: 'status' },
    { type: 'midea_humidifier', operation: 'mode' },
    { type: 'midea_humidifier', operation: 'target_humidity' },

    // 小米/美的 除湿器
    { type: 'mi_dehumidifier', operation: 'online' },
    { type: 'mi_dehumidifier', operation: 'power' },
    { type: 'mi_dehumidifier', operation: 'mode' },
    { type: 'mi_dehumidifier', operation: 'target_humidity' },

    { type: 'midea_dehumidifier', operation: 'online' },
    { type: 'midea_dehumidifier', operation: 'power' },
    { type: 'midea_dehumidifier', operation: 'mode' },
    { type: 'midea_dehumidifier', operation: 'target_humidity' },

    // 小米/美的 空气净化器
    { type: 'mi_air_purifier', operation: 'online' },
    { type: 'mi_air_purifier', operation: 'power' },
    { type: 'mi_air_purifier', operation: 'mode' },
    { type: 'mi_air_purifier', operation: 'fan_level' },

    { type: 'midea_air_purifier', operation: 'online' },
    { type: 'midea_air_purifier', operation: 'power' },
    { type: 'midea_air_purifier', operation: 'mode' },
    { type: 'midea_air_purifier', operation: 'fan_level' },
  ];

  await repo.save(data);
  console.log('[INIT] 控制属性表已初始化完成');
}
